﻿#include "genlib.h"
#include "bucket_sort.h"
#include "benchmark.h"

void bucketSort(int a[], int n, int high) {
	int i, j=0;
	int *count = NewArray(sizeof(int) * high+1, int);
	for(i=0; i<=high; i++)
		count[i] = 0;

	for(i=0; i<n; i++)
		(count[a[i]])++;

	for(i=0; i<=high; i++) {
		for(; benchAddOperation(benchmark) && count[i]>0; (count[i])--) {
			a[j++] = i;
		}
	}
	FreeBlock(count);
}